<%--
  Created by IntelliJ IDEA.
  User: yujiajing
  Date: 2022/10/14
  Time: 9:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page import="com.cn.Mapper.userMapper.UserMapper" %>
<%@ page import="com.cn.util.SqlsesstionUtil" %>
<%@ page import="com.cn.entity.user.User" %>
<%@ page import="java.util.List" %>
<%@ page import="com.cn.Mapper.enployeeMapper.EmployeeMapper" %>
<%@ page import="com.cn.entity.enployee.Employee" %>
<%@ page import="com.cn.Mapper.goodsMapper.GoodsMapper" %>
<%@ page import="com.cn.entity.goods.Goods" %>
<%@ page import="com.cn.Mapper.shopMapper.InventoryMapper" %>
<%@ page import="com.cn.entity.shop.Shop_GoodsInventory" %><%--
  Created by IntelliJ IDEA.
  User: yujiajing
  Date: 2022/10/3
  Time: 14:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>库存视图</title>
    <%--  引入jQuery包  --%>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>

    <!-- 引入layui css -->
    <link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" />

    <!-- 引入layui js -->
    <script src="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>
    <style type="text/css">
        #CardId{
            width: 200px;
            height: 40px;
            float:left;
        }
    </style>
</head>

<body>

<%--<script>
    function ConfirmDelete(id){
        if(confirm("确认删除数据？")){
            OperatorUser(id);

        }
    }

    function OperatorUser(id) {

        $.ajax({

            type : "post",

            url : "employee/delete",

            dateType : "String",

            data : {

                id : id

            },

            success : function(data) {
                alert("删除成功");
                $("#tr_"+id).remove();


            },

            error : function() {
                alert("失败");

                $("#tr_"+id).remove();

            }

        });

    }
</script>--%>

<%
    SqlSession sqlSession = SqlsesstionUtil.getSqlSession();
   InventoryMapper inventoryMapper =sqlSession.getMapper(InventoryMapper.class);
    List<Shop_GoodsInventory> inventoryList= inventoryMapper.showAll();
    %>
<table id="UserTable" class="layui-table"  >

    <tr>
        <td>商品编号</td>
        <td>商品名称</td>
        <td>商品库存</td>
        <td>操作</td>

    </tr>

    <%for (Shop_GoodsInventory goodsInventory :inventoryList ){%>
    <%--  --%>
    <tr id="tr_<%=goodsInventory.getGoods_id()%>">
        <%--    --%>
        <td><%=goodsInventory.getGoods_id()%></td>
        <td><%=goodsInventory.getGoods_name()%></td>
        <td><%=goodsInventory.getGoods_inventory()%></td>

        <td>
            <%--            <a class="layui-btn layui-btn-xs" lay-event="edit" href="UpdateUser.jsp?id=<%=user.getId()%>&username=<%=user.getUsername()%>&password=<%=user.getPassword()%>">编辑</a>--%>
            <a class="layui-btn layui-btn-danger layui-btn-xs"  href="javascript:void(0);"  onclick="inputInventory(<%=goodsInventory.getGoods_id()%>)">进货</a>
        </td>
        <%}%>
    </tr >
</table>
<%--查询模块--%>
<div>
    <form action="" method="post">
        <button class="layui-btn layui-btn-normal" type="submit">查询订单</button>
        <input type="text" id="CardId" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">

    </form>
</div>
<%--查询模块--%>
</body>

<script>
    /**
     * good_id:所要修改的商品id
     * num:所修改的商品数目
     * @param goods_id
     */
    function inputInventory(id){

        var num = prompt("请输入商品数目");
        updateInventory(id,num);

    }
    function updateInventory(id,num) {
        $.ajax({

            type: "post",

            url: "inventory/updateById",

            dateType: "String",

            data: {

                goods_id: id,
                goods_inventory:num

            },

            success: function (data) {
              location.reload();



            },

            error: function () {
                alert("修改失败");


            }

        });


    }
</script>
</html>


